package com.itboye.mengwu.data.presenter;

import java.util.List;
import java.util.Observer;

import com.itboye.core.interfaces.ICompleteListener;
import com.itboye.core.object.BasePresenter;
import com.itboye.core.object.ResultEntity;
import com.itboye.mengwu.data.interfaces.IRedBag;
import com.itboye.mengwu.data.model.RedBagModel;
import com.itboye.mengwu.data.repository.BaseRepository;
import com.itboye.mengwu.data.repository.RedBagRepository;

public class RedBagPresenter extends BasePresenter implements
		IRedBag<RedBagModel> {
	// 红包
	public static final String QueryRedBagSuccess = "_redbag_success";
	public static final String QueryRedBagFail = "_redbag_fail";

	// 红包
	public static final String QueryCouponSuccess = "_Coupon_success";
	public static final String QueryCouponFail = "_Coupon_fail";

	// 计算运费
	public static final String QueryFreightCostSuccess = "_FreightCost_success";
	public static final String QueryFreightCostFail = "_FreightCost_fail";
	
	// 计算商品运费
		public static final String QueryFreightCostGoodsSuccess = "_FreightCostGoods_success";
		public static final String QueryFreightCostGoodsFail = "_FreightCostGoods_fail";

	public RedBagPresenter(Observer observer) {
		super(observer);
		// TODO Auto-generated constructor stub
	}

	// 获取运费
	@Override
	public void add(RedBagModel model) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void delete(RedBagModel model) {
		// TODO Auto-generated method stub

	}

	@Override
	public void update(RedBagModel model) {
		// TODO Auto-generated method stub

	}

	// 红包
	@Override
	public void getInfo(RedBagModel model) {
		// TODO Auto-generated method stub
		IRedBag<RedBagModel> redBag = new RedBagRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(QueryRedBagSuccess);
						RedBagPresenter.this.setChanged();
						RedBagPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						// TODO Auto-generated method stub
						result.setEventTag(Tag_Success);
						result.setEventType(QueryRedBagFail);
						RedBagPresenter.this.setChanged();
						RedBagPresenter.this.notifyObservers(result);
					}
				});
		redBag.getInfo(model);
	}

	// 优惠券
	@Override
	public List<RedBagModel> query(RedBagModel model) {
		// TODO Auto-generated method stub
		IRedBag<RedBagModel> redBag = new RedBagRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(QueryCouponSuccess);
						RedBagPresenter.this.setChanged();
						RedBagPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						// TODO Auto-generated method stub
						result.setEventTag(Tag_Success);
						result.setEventType(QueryCouponFail);
						RedBagPresenter.this.setChanged();
						RedBagPresenter.this.notifyObservers(result);
					}
				});
		redBag.query(model);
		return null;
	}

	@Override
	public void caculateFreightCost(String uid, String addressId, String cartIds) {
		// TODO Auto-generated method stub
		IRedBag<RedBagModel> redBag = new RedBagRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(QueryFreightCostSuccess);
						RedBagPresenter.this.setChanged();
						RedBagPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						// TODO Auto-generated method stub
						result.setEventTag(Tag_Success);
						result.setEventType(QueryFreightCostFail);
						RedBagPresenter.this.setChanged();
						RedBagPresenter.this.notifyObservers(result);
					}
				});
		redBag.caculateFreightCost(uid, addressId, cartIds);
	}

	@Override
	public void caculateFreightCost(String uid, String addressId, String pid,
			String count) {
		// TODO Auto-generated method stub
		IRedBag<RedBagModel> redBag = new RedBagRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						result.setEventTag(Tag_Success);
						result.setEventType(QueryFreightCostGoodsSuccess);
						RedBagPresenter.this.setChanged();
						RedBagPresenter.this.notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						// TODO Auto-generated method stub
						result.setEventTag(Tag_Success);
						result.setEventType(QueryFreightCostGoodsFail);
						RedBagPresenter.this.setChanged();
						RedBagPresenter.this.notifyObservers(result);
					}
				});
		redBag.caculateFreightCost(uid, addressId, pid,count);
		
	}

}
